<template>
  <div>
    <!-- 提现审核 -->

    <!-- 面包屑导航 -->
    <Crumbs></Crumbs>
    <div class="formBox">
      <el-form ref="form" label-width="80px">
        <el-date-picker v-model="value1" type="date" placeholder="选择日期"> </el-date-picker>
        <!-- <el-button plain icon="el-icon-close" style="width:50px"></el-button> -->
        <el-select v-model="region" placeholder="状态" style="width: 20%" @change="screen">
          <el-option label="状态" value="状态"></el-option>
          <el-option label="申请中" value="申请中"></el-option>
          <el-option label="拒绝" value="拒绝"></el-option>
          <el-option label="允许" value="允许"></el-option>
        </el-select>
        <el-input placeholder="请输入内容" v-model="input3" class="input-with-select" style="width: 40%">
          <el-button slot="append" @click="search">筛选</el-button>
        </el-input>
      </el-form>
      <!-- 表格 -->
      <div class="cashTable">
        <template>
          <el-table :data="arr" border style="width: 100%">
            <el-table-column prop="odd" label="提现单号"> </el-table-column>
            <el-table-column prop="awalstore" label="提现门店"> </el-table-column>
            <el-table-column prop="awalnum" label="提现账号"> </el-table-column>
            <el-table-column prop="address" label="提现金额 应到账金额">
              <template v-slot="{ row }">
                <p>{{ row.mount | formatPrice }}</p>
                <p>{{ row.awalreceipt | formatPrice }}</p>
              </template>
            </el-table-column>
            <el-table-column prop="address" label="提现方式">
              <template v-slot="{ row }">
                <p>{{ row.mode }}</p>
                <p>姓名：{{ row.awalname }}</p>
                <p>账号：{{ row.awalnum }}</p>
              </template>
            </el-table-column>
            <el-table-column prop="awaltime" label="提现时间"> </el-table-column>
            <el-table-column prop="awalstate" label="状态">
              <template v-slot="{ row }">
                <div>
                  <span>{{ row.awalstate }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作">
              <template style="display: flex; justify-content: space-around" slot-scope="scope">
                <el-button type="text" size="small" @click="allow(scope.row)">允许</el-button>
                <el-button type="text" size="small" @click="refuse(scope.row)">拒绝</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>

      <!-- 分页 -->
      <div style="heigth: 50px; margin-top: 20px; margin-right: 10px">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="page"
          :page-size="size"
          layout="prev, pager, next"
          :total="tableData.length"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { getXmodifywithdrawalAudit, getXwithdrawalAudit } from '../../api'
import Crumbs from './Crumbs.vue'
import lodash from 'lodash'
export default {
  components: { Crumbs },
  data() {
    return {
      input: '',
      region: '',
      input3: '',
      select: '',
      state: '',
      tableData: [],
      arr: [],
      //日历
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
        shortcuts: [
          {
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            },
          },
          {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            },
          },
          {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            },
          },
        ],
      },
      value1: '',
      // 分页
      total: 0,
      arr: [],
      size: 2,
      page: 1,
      count: 0,
    }
  },
  methods: {
    //允许提现
    allow(row) {
      this.$confirm('确认手动提现完成?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          row.awalstate = '允许'
          getXmodifywithdrawalAudit(row).then((res) => {
            // console.log(res);
          })
          this.$message({
            type: 'success',
            message: '允许成功!',
          })
          // this.fn()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消允许',
          })
        })
    },
    //拒绝提现
    refuse(row) {
      this.$confirm('确认拒绝该提现请求?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          row.awalstate = '拒绝'
          getXmodifywithdrawalAudit(row).then((res) => {
            // console.log(res);
          })
          this.$message({
            type: 'success',
            message: '拒绝允许!',
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消拒绝',
          })
        })
    },
    //状态筛选
    screen() {
      let that = this
      // console.log(this.region);
      if (this.region != '状态') {
        let y = this.tableData.filter(function (obj) {
          return obj.awalstate == that.region
        })
        // console.log(y);
        this.arr = y
      } else {
        this.fn()
      }
    },
    //input筛选
    search() {
      let that = this
      var n = lodash.findIndex(this.tableData, function (o) {
        //判断用户名是否存在
        if (o.awalstore == that.input3) {
          return o.awalstore == that.input3
        } else if (o.awalname == that.input3) {
          return o.awalname == that.input3
        } else if (o.awalstate == that.input3) {
          return o.awalstate == that.input3
        }
      })
      //  console.log(n);
      this.arr = [this.tableData[n]]
    },
    // 分页
    fn() {
      getXwithdrawalAudit().then((res) => {
        this.arr = res.data.slice((this.page - 1) * this.size, this.page * this.size)
        this.tableData = res.data
        this.count = res.data.length //总条数
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.page = val
      this.fn()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.page = val
      this.fn()
    },
  },
  created() {
    this.fn()
  },
}
</script>

<style lang="scss" scoped>
.formBox {
  width: 85%;
  margin: auto;
  .cashTable {
    margin-top: 50px;
    .el-table th.el-table__cell {
      background: lightgrey;
    }
  }
}
</style>
